home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  19.8 KB  |  818 lines

  1. #include "includes.h"
  2. #include "HTML.h"
  3. #include "mosaic.h"
  4. #include "globals.h"
  5. #include "htmlgad.h"
  6. #include "gui.h"
  7. #include <dos.h>
  8. #include <stat.h>
  9. #include "XtoI.h"
  10. #include "HTMLP.h"
  11. #include "protos.h"
  12. #include "TextEditField.h"
  13.  
  14. #include "amosaic_cat.h"
  15. struct Library *LocaleBase;
  16.  
  17. #include "AboutPic.h"
  18.  
  19. void __regargs _CXBRK(void);
  20.  
  21. extern ULONG HookEntry();
  22.  
  23. extern AppData Rdata;
  24. extern __far int WWW_TraceFlag;
  25.  
  26. //char *statuspage="http://insti.physics.sunysb.edu/AMosaic/";
  27.  
  28. int DEBUG;
  29. extern char *cached_url;
  30. extern char *home_document;
  31. extern char *startup_document;
  32. extern long HTMLFormImages;
  33.  
  34. int lib_version;
  35. char *url, *canon, *title, *tmp;
  36. char *text, *texthead, *ref;
  37. mo_window window;
  38.  
  39. struct MsgPort *FileNotifyPort;
  40. ULONG FileNotifySigBit;
  41.  
  42. void amiga_init_hooks(void);
  43. static void locate_mime_files(void);
  44. void PasteStringClipBoard(char *string);
  45.  
  46. //#define TRACE_INPUT
  47.  
  48. /*------------------------------------------------------------------------
  49.   Initialize everything, load an initial URL, and enter main loop.
  50. ------------------------------------------------------------------------*/
  51.  
  52. void main(int argc, char **argv)
  53. {
  54.     BOOL running=TRUE;
  55.     ULONG signal;
  56.     int blue1, blue2, red;
  57.     struct Screen *scr;
  58.     HTMLGadClData *inst;
  59.     struct Window *win;
  60.     int transfer_in_progress=0;
  61.  
  62.     /* A LOT OF THE STUFF AT THE TOP HERE SHOULD BE MOVED EVENTUALLY! */
  63.  
  64.     lib_version = IntuitionBase->LibNode.lib_Version;
  65.     //    lib_version = 38;        // for testing WB2.x compatibilty on 3.x machines
  66.  
  67.         if (lib_version < 39) {
  68.         printf("Requires WB 3.0 or later\n") ;
  69.         exit(0) ;
  70.         }
  71.  
  72.     LocaleBase=OpenLibrary("locale.library",38);
  73.     OpenamosaicCatalog(NULL,NULL);
  74.  
  75.     amiga_init_hooks();
  76.     amiga_load_prefs();        /* RData is extern'ed */
  77.     locate_mime_files();
  78.     mo_setup_global_history();
  79.  
  80.     /* Use the new 6.50 WB argument support. */
  81.     if (argc == 0) {
  82.         argc = _WBArgc;
  83.         argv = _WBArgv;
  84.     }
  85.  
  86.     if ((argc > 1) && (!strcmp(argv[1], "-x"))) {
  87.             argc -= 1 ;
  88.         argv += 1 ;
  89.         DEBUG = 1;
  90.     }
  91.  
  92.     WWW_TraceFlag = DEBUG;
  93.  
  94.     fire_er_up(argc, argv);
  95.  
  96.     if (startup_document)
  97.         url = strdup(startup_document);
  98.     else
  99.     url = strdup(home_document);
  100.  
  101.     setup_win(&window);        /* this is just an internal structure */
  102.  
  103. #ifdef TRACE_INPUT
  104.     printf("Loading fonts... ");
  105.     fflush(stdout);
  106. #endif
  107.  
  108.     open_fonts();            /* open our set of fonts */
  109.  
  110. #ifdef TRACE_INPUT
  111.     printf("Ok.\n");
  112. #endif
  113.  
  114.     init();                    /* Initialize MUI itself */
  115.     MUI_HTMLGadClass = HTMLGadClInit(); /* Initialize our new gadget class */
  116.     HTMLGadClass=MUI_HTMLGadClass->mcc_Class;
  117.     SpinnerClass = SpinnerClInit(); /* Initialize the spinner class */
  118.     BoingTransferClass = BoingTransferClInit(); /* Initialize the spinner class */
  119.     MUI_NewGroupClass=NewGroupClInit();
  120.     NewGroupClass=MUI_NewGroupClass->mcc_Class;
  121.     TextEditFieldClass=TextEditFieldClInit();
  122.     if(FileNotifyPort=CreatePort(NULL,0))
  123.         FileNotifySigBit=1<<(FileNotifyPort->mp_SigBit);
  124.     else
  125.         printf("Couldn't create notify port\n");
  126.  
  127.  
  128.     mui_init();            /* Initialize the interface */
  129.  
  130.     if (lib_version >= 39) {
  131.  
  132.     /* Find out what screen we are on.    If it is not the workbench screen,
  133.          release all the pens on the screen!    This is a hack until we decide
  134.          on another way to get pubscreens with shareable pens. */
  135.         }
  136.  
  137.     DoMethod(BT_Forward, MUIM_Set, MUIA_Disabled, TRUE);
  138.     DoMethod(BT_Back, MUIM_Set, MUIA_Disabled, TRUE);
  139.  
  140.     window.HTML_Gad = HTML_Gad;
  141.     window.scrolled_win = INST_DATA(HTMLGadClass,HTML_Gad);
  142.     window.view = WI_Main;
  143.  
  144.     get(HTML_Gad, HTMLA_inst, (ULONG *)(&inst));
  145. //    window.scrolled_win=inst;
  146.  
  147.     Rdata.track_pointer_motion=0;
  148.     mo_access_document(&window, url);
  149.     Rdata.track_pointer_motion=1;
  150.  
  151.  
  152.     /* */
  153.     /* THIS IS THE MAIN APPLICATION INPUT LOOP */
  154.     /* */
  155.  
  156.     while (running) {
  157.         extern ULONG RexxSignalBits ;
  158.         void RexxDispatch(void) ;
  159.         int a;
  160.  
  161. #ifdef TRACE_INPUT
  162.     kprintf("Entering MUI input loop\n");
  163. #endif
  164.         a = (DoMethod(App,MUIM_Application_Input,&signal));
  165.  
  166. #ifdef TRACE_INPUT
  167.     kprintf("Exiting MUI input loop\n");
  168. #endif
  169.  
  170.         signal |= RexxSignalBits;
  171. /* | FileNotifySigBit); */
  172.         switch(a) {
  173.         
  174.             
  175.         case mo_exit_program:
  176.         case MUIV_Application_ReturnID_Quit:
  177.         running = FALSE;
  178.         break;
  179.  
  180.     case mo_about:{
  181.         extern char * amosaic_about_version;
  182.         Object *win,*ok_gad,*omni_gad;
  183.         BOOL about_running=TRUE;
  184.         ULONG signals;
  185.         win=WindowObject,
  186.             MUIA_Window_Title,GetamosaicString(MSG_REQ_ABOUT_TITLE),
  187.             MUIA_Window_RefWindow,WI_Main,
  188.             MUIA_Window_CloseGadget,FALSE,
  189.             WindowContents,VGroup,
  190.                 MUIA_Background,MUII_RequesterBack,
  191.                 Child,VGroup,
  192.                     Child,HGroup,
  193.                         TextFrame,
  194.                         MUIA_Weight,0,
  195.                         MUIA_Group_Spacing,0,
  196.                         MUIA_Background,MUII_BACKGROUND,
  197.                         Child,HSpace(0),        
  198.                         Child,BodychunkObject,
  199.                             MUIA_Bodychunk_Body,amlogo_body,
  200.                             MUIA_Bodychunk_Compression,AMLOGO_COMPRESSION,
  201.                             MUIA_Bodychunk_Depth,AMLOGO_DEPTH,
  202.                             MUIA_Bodychunk_Masking,AMLOGO_MASKING,
  203.                             MUIA_Bitmap_Width,AMLOGO_WIDTH,
  204.                             MUIA_Bitmap_Height,AMLOGO_HEIGHT,
  205.                             MUIA_Bitmap_SourceColors,amlogo_colors,
  206. //                            MUIA_Bitmap_Transparent,0,
  207.                             MUIA_FixWidth,AMLOGO_WIDTH,
  208.                             MUIA_FixHeight,AMLOGO_HEIGHT,
  209.                             End,
  210.                         Child,HSpace(0),
  211.                         End,
  212.                     Child,HGroup,
  213.                         MUIA_Group_Spacing,0,
  214.                         TextFrame,
  215.                         MUIA_Background,MUII_TextBack,
  216.                         MUIA_Weight,0,
  217.                         Child,HSpace(0),
  218.                         Child,TextObject,MUIA_Text_PreParse,"\033c",MUIA_Text_Contents,amosaic_about_version,MUIA_Text_SetMax,TRUE,End,
  219.                         Child,HSpace(0),
  220.                         End,
  221.                     Child,omni_gad=TextObject,MUIA_Text_PreParse,"\033c",
  222.                         MUIA_Text_Contents,"http://www.omnipresence.com/",
  223.                         ButtonFrame,MUIA_Background,MUII_ButtonBack,MUIA_InputMode,MUIV_InputMode_RelVerify,
  224.                         MUIA_FixWidthTxt,"  http://www.omnipresence.com/  ",
  225.                         End,
  226.                     End,
  227.                 Child,HGroup,
  228.                     MUIA_Weight,0,
  229.                     Child,HSpace(0),
  230.                     Child,ok_gad=SimpleButton(GetamosaicString(MSG_REQ_ABOUT_OK)),
  231.                     Child,HSpace(0),
  232.                     End,
  233.                 End,
  234.             End;                             
  235.  
  236.         if(win)
  237.         {
  238.             DoMethod(App,OM_ADDMEMBER,win);
  239.             DoMethod(ok_gad,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,1);
  240.             DoMethod(omni_gad,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,2);
  241.             set(win,MUIA_Window_ActiveObject,ok_gad);
  242.             set(App,MUIA_Application_Sleep,TRUE);
  243.             set(win,MUIA_Window_Open,TRUE);
  244.             while(about_running)
  245.             {
  246.                 switch(DoMethod(App,MUIM_Application_Input,&signals))
  247.                 {
  248.                     case MUIV_Application_ReturnID_Quit:
  249.                         running=FALSE;
  250.                     case 1:
  251.                         about_running=FALSE;
  252.                         break;
  253.                     case 2:
  254.                         set(TX_URL, MUIA_String_Contents,"http://www.omnipresence.com/");
  255.                         DoMethod(App,MUIM_Application_ReturnID,ID_STRINGURL);
  256.                         about_running=FALSE;
  257.                         break;
  258.                 }
  259.                 if(about_running&&signals) Wait(signals);
  260.             }
  261.             set(win,MUIA_Window_Open,FALSE);
  262.             set(App,MUIA_Application_Sleep,FALSE);
  263.             DoMethod(App,OM_REMMEMBER,win);
  264.             MUI_DisposeObject(win);
  265.             }                    
  266.         }         
  267.         break;
  268.  
  269.     case mo_search_index:{
  270.         char *str, *esc_str;
  271.         int len = strlen(cached_url);
  272.  
  273.         get(STR_Search, MUIA_String_Contents, &str);
  274.         esc_str = mo_escape_part(str);
  275.         url = malloc(len + strlen(esc_str) + 5);
  276.         strcpy(url, cached_url);
  277.         strtok(url, "#");
  278.         strtok(url, "?");
  279.         if (url[strlen(url)-1] != '?'){
  280.                 strcat (url, "?");
  281.             }
  282.         strcat(url, esc_str);
  283.         free(esc_str);
  284.                 set(HTML_Gad, HTMLA_active, FALSE);
  285. //        inst->html->active = FALSE;
  286.         mo_access_document(&window, url);
  287.                 set(HTML_Gad, HTMLA_active, TRUE);
  288. //        inst->html->active = TRUE;
  289.         set(STR_Search, MUIA_String_Contents, NULL);
  290.         break;
  291.         }
  292.  
  293.         case ID_STRINGURL:{
  294.             int i = transfer_in_progress;
  295.  
  296.             get(TX_URL, MUIA_String_Contents, (ULONG *)(&tmp));
  297.             url = malloc(strlen(tmp)+1);
  298.             strcpy(url, tmp);
  299.             transfer_in_progress = 1;
  300.             set(HTML_Gad, HTMLA_active, FALSE);
  301.             Rdata.track_pointer_motion=0;
  302.             if (!i) mo_access_document(&window, url);
  303.             Rdata.track_pointer_motion=1;
  304.             set(HTML_Gad, HTMLA_active, TRUE);
  305.             break;
  306.         }
  307.  
  308.         case ID_GOTOANCHOR:{
  309.         int i = transfer_in_progress;
  310.  
  311.         GetAttr(HTMLA_new_href, HTML_Gad, (ULONG *)(&tmp));
  312.         url = malloc(strlen(tmp)+1);
  313.         strcpy(url, tmp);
  314.         transfer_in_progress = 1;
  315.         set(HTML_Gad, HTMLA_active, FALSE);
  316.         Rdata.track_pointer_motion=0;
  317.         if (!i) mo_access_document(&window, url);
  318.         Rdata.track_pointer_motion=1;
  319.                 set(HTML_Gad, HTMLA_active, TRUE);
  320.         break;
  321.         }
  322.  
  323.         case ID_GETTEXT:{
  324.         int i = transfer_in_progress;
  325.  
  326.         GetAttr(HTMLA_get_href, HTML_Gad, (ULONG *)(&tmp));
  327.         url = malloc(strlen(tmp)+1);
  328.         strcpy(url, tmp);
  329.         transfer_in_progress = 1;
  330.         set(HTML_Gad, HTMLA_active, FALSE);
  331.         Rdata.track_pointer_motion=0;
  332.         if (!i) mo_access_document(&window, url);
  333.         Rdata.track_pointer_motion=1;
  334.                 set(HTML_Gad, HTMLA_active, TRUE);
  335.         break;
  336.         }
  337.  
  338.         case ID_POSTTEXT:{
  339.         int i = transfer_in_progress;
  340.         char *query;
  341.         GetAttr(HTMLA_post_href, HTML_Gad, (ULONG *)(&tmp));
  342.         url = malloc(strlen(tmp)+1);
  343.         strcpy(url, tmp);
  344.         free(tmp); /* Yes, it is legal to free it here */
  345.  
  346.         GetAttr(HTMLA_post_text, HTML_Gad, (ULONG *)(&tmp));
  347.         query = malloc(strlen(tmp)+1);
  348.         strcpy(query, tmp);
  349.         free(tmp); /* Yes, it is legal to free it here */
  350.  
  351.         transfer_in_progress = 1;
  352.         set(HTML_Gad, HTMLA_active, FALSE);
  353.         Rdata.track_pointer_motion=0;
  354.         if (!i) mo_post_access_document(&window, url,
  355.             "application/x-www-form-urlencoded", query); /* All forms post have a _post in the name */
  356.                 set(HTML_Gad, HTMLA_active, TRUE);
  357.         Rdata.track_pointer_motion=1;
  358.         break;
  359.         }
  360.  
  361.         case mo_macro: case mo_macro_1: case mo_macro_2: case mo_macro_3:
  362.         case mo_macro_4: case mo_macro_5: case mo_macro_6: case mo_macro_7:
  363.         case mo_macro_8: case mo_macro_9: case mo_macro_10:
  364.         case mo_add_hot_list: case mo_jump_hot_list: case mo_print_document:
  365.         RexxLaunch(a - mo_macro_1, &window);
  366.         break;
  367.  
  368.     case mo_back:
  369.         mo_back_node(&window);
  370.         break;
  371.  
  372.     case mo_forward:
  373.         mo_forward_node(&window);
  374.         break;
  375.  
  376.     case mo_home_document:
  377.         mo_access_document(&window, home_document);
  378.         break;
  379.  
  380.     case mo_load_amigahome:
  381.         Rdata.track_pointer_motion=0;
  382.         mo_access_document(&window, "http://www.omnipresence.com/amiga/");
  383.         Rdata.track_pointer_motion=1;
  384.         break;
  385.  
  386.     case mo_load_amosaichome:
  387.         Rdata.track_pointer_motion=0;
  388.         mo_access_document(&window, "http://www.omnipresence.com/amosaic/");
  389.         Rdata.track_pointer_motion=1;
  390.         break;
  391.  
  392.     case mo_reload_document:
  393.         Rdata.track_pointer_motion=0;
  394.         mo_reload_window_text(&window, 0);
  395.         Rdata.track_pointer_motion=1;
  396.         break;
  397.  
  398.     case mo_search:
  399.         mo_post_search_window(&window);
  400.         break; 
  401.  
  402.     case mo_save_document:
  403.         mo_post_save_window(&window);
  404.         break;
  405.  
  406.     case mo_clear_image_cache:{
  407.         struct Gadget *g;
  408.         struct Windwo *w;
  409.         TO_HTML_FlushImageCache();
  410.  
  411. //mjw    mo_flush_image_cache(&window);
  412. //mjw    GetAttr(MUIA_Boopsi_Object, HTML_Gad, (ULONG *)(&g));
  413. //mjw    GetAttr(MUIA_Window_Window, WI_Main, (ULONG *)(&w));
  414. //mjw    RefreshGList(g, w, NULL, 1);
  415.         }
  416.         break;
  417.  
  418.     case mo_expand_images_current:
  419.         /* if (window.delay_image_loads) */ LoadInlinedImages();
  420.         break;
  421.  
  422. //    case ID_MUIRESIZE:
  423. //        ResetAmigaGadgets();
  424. //        break;
  425.  
  426.     case mo_clear_global_history:
  427.         mo_wipe_global_history(&window);
  428.         break;
  429.  
  430.     case mo_open_document:
  431.         mo_post_open_window(&window);
  432.         break;
  433.  
  434.     case mo_open_local_document:
  435.         if (get_filename(&url)) {
  436.             char *url2;
  437.             url2 = malloc(strlen(url)+2);
  438.             strcpy(url2, "/");
  439.             strcat(url2, url);
  440.             url = mo_url_canonicalize_local(url2);
  441.             Rdata.track_pointer_motion=0;
  442.             mo_load_window_text(&window, url, NULL);
  443.             Rdata.track_pointer_motion=1;
  444.             }
  445.         break;
  446.  
  447.     case mo_document_source:
  448.         mo_post_source_window(&window);
  449.         break;
  450.  
  451.     case mo_history_list:
  452.         mo_post_history_win(&window);
  453.         break;
  454.  
  455.     case mo_delay_image_loads:
  456.         window.delay_image_loads = DoMethod(App, MUIM_Application_GetMenuCheck, mo_delay_image_loads);
  457.         if (!window.delay_image_loads) LoadInlinedImages();
  458.         break;
  459.  
  460.     case mo_image_buttons:
  461.     case mo_buttons_text:
  462.     case mo_buttons_image:
  463.     case mo_buttons_imagetext:
  464.         if(DoMethod(App, MUIM_Application_GetMenuCheck, mo_buttons_text))
  465.             Rdata.image_buttons = 0;
  466.         else if(DoMethod(App, MUIM_Application_GetMenuCheck, mo_buttons_image))
  467.             Rdata.image_buttons = 1;
  468.         else if(DoMethod(App, MUIM_Application_GetMenuCheck, mo_buttons_imagetext))
  469.             Rdata.image_buttons = 2;
  470.  
  471.         SetImageButtons(Rdata.image_buttons);
  472.         break;
  473.  
  474.     case mo_isindex_to_form:
  475.         Rdata.isindex_to_form = DoMethod(App, MUIM_Application_GetMenuCheck, mo_isindex_to_form);
  476.         SetSearchIndex(Rdata.image_buttons);
  477.         mo_set_win_current_node(&window,window.current_node);
  478.         break;
  479.  
  480.     case mo_url_to_clipboard:
  481.         get(TX_URL, MUIA_String_Contents, (ULONG *)(&tmp));
  482.         PasteStringClipBoard(tmp);    
  483.         break;
  484.  
  485.     case mo_binary_transfer:
  486.         window.binary_transfer = DoMethod(App, MUIM_Application_GetMenuCheck, mo_binary_transfer);
  487.         break;
  488.  
  489.     case mo_show_form_images:{
  490.         HTMLGadClData *inst=INST_DATA(HTMLGadClass,HTML_Gad);
  491.         inst->have_formsI=1;
  492.         set(WI_Main,MUIA_Window_Open,FALSE);
  493.         set(WI_Main,MUIA_Window_Open,TRUE);
  494.         set(WI_ImagesReady,MUIA_Window_Open,FALSE);
  495.         inst->have_formsI=0;}
  496.         break;
  497.  
  498. //    case ID_CONFIGSCROLLBARS:
  499. //        ResetAmigaGadgets();
  500. //        break;
  501.  
  502.     case ID_IMAGELOAD:
  503.         if (lib_version < 39)    /* need WB 3.x */
  504.             break;
  505.         {
  506.             char *img;
  507.             int i=transfer_in_progress;
  508.  
  509.             transfer_in_progress = 1;
  510.             if (!i) {
  511.                 char *img;
  512.                 HTMLFormImages=0;
  513.                 get(HTML_Gad, HTMLA_image_load, &img);
  514.                 Rdata.track_pointer_motion=0;
  515.                 LoadInlinedImage(img);
  516.                 Rdata.track_pointer_motion=1;
  517.                 if(inst->have_forms && HTMLFormImages)
  518.                     set(WI_ImagesReady,MUIA_Window_Open,TRUE);
  519.                 }
  520.         }
  521.         break;
  522.     }
  523.  
  524.     if (signal)
  525.         transfer_in_progress = 0;
  526. #ifdef    TRACE_INPUT
  527.     if(signal & SIGBREAKF_CTRL_C)
  528.         kprintf("Ctrl C pressed\n");
  529. #endif
  530.  
  531.     if (running && signal) {
  532.         ULONG sig_rec;
  533. #ifdef TRACE_INPUT
  534.         kprintf("Waiting for signals\n");
  535. #endif
  536.         sig_rec=Wait(signal | FileNotifySigBit);
  537. #ifdef TRACE_INPUT
  538.         kprintf("Exit waiting for signals\n");
  539. #endif
  540.         if ((sig_rec /* & (~FileNotifySigBit) */ ) && RexxSignalBits)
  541.             RexxDispatch();
  542.  
  543.         else if (sig_rec & FileNotifySigBit){
  544.             struct NotifyMessage *msg;
  545. #ifdef TRACE_INPUT
  546.             kprintf("Getting filenotify sig\n");
  547. #endif
  548.             while(msg=(struct NotifyMessage *)GetMsg(FileNotifyPort)){
  549.                 Object *obj=(Object *)msg->nm_NReq->nr_UserData;
  550. #ifdef TRACE_INPUT
  551.                 kprintf("Getting filenotify msg for object %08lx\n",obj);
  552. #endif
  553.                 ReplyMsg((struct Message *)msg);
  554.                 DoMethod(obj,MUIM_TEF_FileChange);
  555.                 }
  556.             }
  557.         }
  558. #ifdef TRACE_INPUT
  559.         else
  560.             kprintf("No signal to wait for\n");
  561. #endif
  562.     }
  563.     mo_flush_image_cache(&window);
  564.  
  565.  
  566. /*
  567.     set(WI_Main,MUIA_Window_Open,FALSE);
  568.  
  569.     {
  570.         extern void ForgetALLHTMLAmigaData    (void);
  571.         ForgetALLHTMLAmigaData();
  572.     }
  573. */
  574.  
  575.  
  576.     DoMethod(App,OM_REMMEMBER,WI_Main); /* We HAVE to close and dispose the window before we free the classes */
  577.     MUI_DisposeObject(WI_Main);
  578.  
  579.  
  580.     if(FileNotifyPort)
  581.         DeletePort(FileNotifyPort); /* All pending messages are deleted by EndNotify */
  582.     TextEditFieldClFree(TextEditFieldClass);
  583.     BoingTransferClFree(BoingTransferClass);
  584.     SpinnerClFree(SpinnerClass);
  585.     HTMLGadClFree(MUI_HTMLGadClass);
  586.     NewGroupClFree(MUI_NewGroupClass);
  587.     
  588.     close_fonts();            /* dispose our set of fonts */
  589.  
  590.  
  591.     if (Rdata.use_global_history)
  592.         mo_write_global_history();
  593.  
  594.     RexxQuit() ;
  595.  
  596.     CloseamosaicCatalog();
  597.     if(LocaleBase)
  598.         CloseLibrary(LocaleBase);
  599.  
  600.     fail(App,NULL);
  601. }
  602.  
  603.  
  604.  
  605. /*------------------------------------------------------------------------
  606.     Open requester and get the name of a local file to load.
  607. ------------------------------------------------------------------------*/
  608. int get_filename(char **name)
  609. {
  610.     struct FileRequester *fr;
  611.     struct Window *w=NULL;
  612.     int result;
  613.     char *f;
  614.  
  615.     fr = MUI_AllocAslRequestTags(ASL_FileRequest, ASL_Hail, GetamosaicString(MSG_REQ_OPEN_LOCAL_TITLE),
  616.                          TAG_DONE);
  617.     GetAttr(MUIA_Window_Window, WI_Main, (ULONG *)(&w));
  618.     result = MUI_AslRequestTags(fr, ASLFR_Window, w, TAG_DONE);
  619.     if (result) {
  620.         f = malloc(255);
  621.         getcd(0, f);
  622.         AddPart(f, fr->rf_Dir, 200);
  623.         AddPart(f, fr->rf_File, 200);
  624.         *name = strdup(f);
  625.         free(f);
  626.     }
  627.     MUI_FreeAslRequest(fr);
  628.     return result;
  629. }
  630.  
  631.  
  632.  
  633. void setup_win(struct mo_window *win)
  634. {
  635.     win->id = 0;
  636.     win->history = NULL;
  637.     win->current_node = NULL;
  638.     win->reloading = 0;
  639.     win->target_anchor = NULL;
  640.     win->underlines = 1;
  641.     win->visited_underlines = 1;
  642.     win->cached_url = NULL;
  643.     win->search_start = (void *)TO_HTMLMakeSpaceForElementRef();
  644. //    win->search_start = (void *)malloc(sizeof (ElementRef));
  645.     win->search_end = (void *)TO_HTMLMakeSpaceForElementRef();
  646. //    win->search_end = (void *)malloc(sizeof (ElementRef));
  647.     win->binary_transfer = 0;
  648.     win->delay_image_loads = Rdata.delay_image_loads;
  649. }
  650.  
  651.  
  652. /*
  653.     Tell libwww what screen to open external viewers on
  654. */
  655. char *gui_whichscreen(void)
  656. {
  657.     struct Screen *scr;
  658.     struct PubScreenNode *p;
  659.     struct List *l;
  660.     char *name;
  661.  
  662.     get(WI_Main, MUIA_Window_Screen, &scr);
  663.     l = LockPubScreenList();
  664.     for (p = (struct PubScreenNode *)(l->lh_Head); p != NULL;
  665.              p = (struct PubScreenNode *)(p->psn_Node.ln_Succ)) {
  666.         if (p->psn_Screen == scr) name = p->psn_Node.ln_Name;
  667.     }
  668.     UnlockPubScreenList();
  669.     
  670.     return(name);
  671. }
  672.  
  673.  
  674. unsigned long back_node_cb(void)
  675. {
  676.     mo_back_node(&window);
  677.     return (unsigned long) 0;
  678. }
  679.  
  680. unsigned long forward_node_cb(void)
  681. {
  682.     mo_forward_node(&window);
  683.     return (unsigned long) 0;
  684. }
  685.  
  686. /*
  687. extern unsigned long update_debug_cb(void);
  688. */
  689.  
  690. extern unsigned long icon_pressed_cb(void);
  691.  
  692. void amiga_init_hooks(void)
  693. {
  694. /*    debug_hook.h_Entry = HookEntry;
  695.     debug_hook.h_SubEntry = update_debug_cb;
  696.     debug_hook.h_Data = NULL;
  697. */
  698.     interrupt_hook.h_Entry = HookEntry;
  699.     interrupt_hook.h_SubEntry = icon_pressed_cb;
  700.     interrupt_hook.h_Data = NULL;
  701.  
  702.     goback_hook.h_Entry = HookEntry;
  703.     goback_hook.h_SubEntry = back_node_cb;
  704.     goback_hook.h_Data = NULL;
  705.  
  706.     goforward_hook.h_Entry = HookEntry;
  707.     goforward_hook.h_SubEntry = forward_node_cb;
  708.     goforward_hook.h_Data = NULL;
  709. }
  710.  
  711. //void __regargs _CXBRK(void)
  712. //{
  713. //}
  714.  
  715.  
  716. /* MWM
  717.      Apparently we have lots of places to look for MIME files.    Blech.
  718. */
  719. static void locate_mime_files(void)
  720. {
  721.     extern char *global_extension_map;
  722.     extern    char *global_type_map;
  723.     /* the places to be searched, in decreasing order of desirability */
  724.     static char *extension_map_places[6]={
  725.         "env:mosaic/mime.types",        "env:mosaic/.mime.types",
  726.         "env:mime.types",        "env:.mime.types",
  727.         "s:mime.types",        "s:.mime.types"
  728.         };
  729.  
  730.     static char *type_map_places[6]={
  731.         "env:mosaic/mailcap",        "env:mosaic/.mailcap",
  732.         "env:mailcap",        "env:.mailcap",
  733.         "s:mailcap",        "s:.mailcap"
  734.         };
  735.  
  736.  
  737.     /* only mess with it if it is set to the default or unset */
  738.     if ((global_extension_map == NULL) ||
  739.             (! stricmp("s:.mime.types",global_extension_map))){
  740.         FILE *test; int i;
  741.         for (i=0; i<6; i++)
  742.             if ((FILE *)NULL !=(test=fopen(extension_map_places[i],"r"))){
  743.     fclose(test);
  744.     global_extension_map = extension_map_places[i];
  745.                 break;
  746.             }
  747.     }
  748.     /* only mess with it if it is set to the default or unset */
  749.     if ((global_type_map == NULL) ||
  750.             (! stricmp("s:.mailcap",global_type_map))){
  751.         FILE *test; int i;
  752.         for (i=0; i<6; i++)
  753.             if ((FILE *)NULL !=(test=fopen(type_map_places[i],"r"))){
  754.     fclose(test);
  755.     global_type_map = type_map_places[i];
  756.                 break;
  757.             }
  758.     }
  759. }
  760.  
  761. //mjw sleep() { }
  762.  
  763.  
  764. void WriteLong(struct IOStdReq *ior,long *ldata)
  765. {
  766.     ior->io_Data = ldata;
  767.     ior->io_Length = 4;
  768.     ior->io_Command = CMD_WRITE;
  769.     DoIO((struct IORequest *)ior);
  770. }
  771.  
  772. void PasteStringClipBoard(char *string)
  773. {
  774.     struct MsgPort *ReplyPort;
  775.     struct IOStdReq *ior;
  776.     long unit=0,slen,length;
  777.     BOOL odd=FALSE;
  778.  
  779.     if(ReplyPort=CreateMsgPort()){
  780.         if(ior=(struct IOStdReq *)CreateExtIO(ReplyPort,sizeof(struct IOClipReq))){
  781.             if(!OpenDevice("clipboard.device",unit,(struct IORequest *)ior,NULL)){
  782.  
  783.                 slen=strlen(string);
  784.                 odd= slen & 1;
  785.                 length=(slen+13) & ~1;
  786.  
  787.                 ior->io_Offset=0;
  788.                 ior->io_Error=0;
  789.                 ((struct IOClipReq *)ior)->io_ClipID=0;
  790.  
  791.                 WriteLong(ior,(LONG *)"FORM");
  792.                 WriteLong(ior,&length);
  793.                 WriteLong(ior,(LONG *)"FTXT");
  794.                 WriteLong(ior,(LONG *)"CHRS");
  795.                 WriteLong(ior,&slen);
  796.  
  797.                 ior->io_Data = string;
  798.                 ior->io_Length = slen;
  799.                 ior->io_Command = CMD_WRITE;
  800.                 DoIO((struct IORequest *)ior);
  801.                 if(odd){
  802.                     ior->io_Data = "";
  803.                     ior->io_Length = 1L;
  804.                     ior->io_Command = CMD_WRITE;
  805.                     DoIO((struct IORequest *)ior);
  806.                     }
  807.  
  808.                 ior->io_Command = CMD_UPDATE;
  809.                 DoIO((struct IORequest *)ior);
  810.  
  811.                 CloseDevice((struct IORequest *)ior);
  812.                 }
  813.             DeleteExtIO((struct IORequest *)ior);
  814.             }
  815.         DeleteMsgPort(ReplyPort);
  816.         }
  817. }
  818.